
//<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
//<uses-permission android:name="android.permission.RECORD_AUDIO" />
//<uses-permission android:name="android.permission.STORAGE" />
//<uses-permission android:name="android.permission.CAMERA" />

package com.walkerma.library;

import android.app.Activity;
import android.content.Context;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraManager;
import android.media.MediaRecorder;


public class MediaProcess {
	public static void prepareAudioRecorder(MediaRecorder audioRec, String strOutFile){
		audioRec.setAudioSource(MediaRecorder.AudioSource.MIC);
		audioRec.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
		audioRec.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
		audioRec.setOutputFile(strOutFile);
		//		try {
		//			audioRec.prepare();
		//			audioRec.start();
		//		} catch (IllegalStateException e) {
		//			// TODO Auto-generated catch block
		//			e.printStackTrace();
		//		} catch (IOException e) {
		//			// TODO Auto-generated catch block
		//			e.printStackTrace();
		//		}		
		//		audioRec.stop();
	}

	public static void prepareVideoRecorder(MediaRecorder videoRec, String strOutFile){
		videoRec.setVideoSource(MediaRecorder.VideoSource.CAMERA);
		videoRec.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
		videoRec.setAudioEncoder(MediaRecorder.OutputFormat.MPEG_4);
		//videoRec.setVideoFrameRate(rate);
		//videoRec.setVideoSize(width, height)
		videoRec.setOutputFile(strOutFile);
	}




	//////////////////////////////////////////////////////////////////
	/*                      Permission Process                      */
	//////////////////////////////////////////////////////////////////
	//	public boolean checkPermission() {
	//		int result = checkSelfPermission(WRITE_EXTERNAL_STORAGE);
	//		int result1 = checkSelfPermission(RECORD_AUDIO);
	//		return result == PackageManager.PERMISSION_GRANTED && 
	//				result1 == PackageManager.PERMISSION_GRANTED;
	//	}
	//
	//	private void requestPermission() {
	//		import static android.Manifest.permission.RECORD_AUDIO;
	//		import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
	//		requestPermissions(new String[]{WRITE_EXTERNAL_STORAGE, RECORD_AUDIO},
	//				RequestPermissionCode);
	//	}
	//
	//	@Override
	//	public void onRequestPermissionsResult(int requestCode, 
	//			String permissions[], int[] grantResults) {
	//		switch (requestCode) {
	//		case RequestPermissionCode:
	//			if (grantResults.length> 0) {
	//				boolean StoragePermission = grantResults[0] == 
	//						PackageManager.PERMISSION_GRANTED;
	//				boolean RecordPermission = grantResults[1] == 
	//						PackageManager.PERMISSION_GRANTED;
	//
	//				if (StoragePermission && RecordPermission) {
	//					Toast.makeText(MainActivity.this, "Permission Granted", 
	//							Toast.LENGTH_LONG).show();
	//				} else {
	//					Toast.makeText(MainActivity.this,"Permission Denied",Toast.LENGTH_LONG).show();
	//				}
	//			}
	//			break;
	//		}
	//	}

	public static String[] getCameraArray(Activity activity){
		CameraManager cm = (CameraManager)activity
				.getSystemService(Context.CAMERA_SERVICE);
		String[] cameraIdList = null;
		try {
			cameraIdList = cm.getCameraIdList();	// API 21
		} catch (CameraAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return cameraIdList;
	}

}
